package vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import controlador.Sistema;



public class ReporteResultado extends javax.swing.JFrame {
	private static final long serialVersionUID = 1L;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JButton jButton1;
	private Logo jPanel1;
	private JTextField jTextField1;
	private JButton jButton4;
	private JComboBox jComboBox1;
	private JButton jButton3;
	private JLabel jLabel3;
	private JButton jButton2;
	private static ReporteResultado instancia;
	
	
	public static ReporteResultado getInstancia() {
		if(instancia == null)
			return new ReporteResultado();
		return instancia;
	}

	
	private ReporteResultado() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			final String[] proyectos = Sistema.getInstancia().buscarProyecto();
			this.setTitle("Reporte de Resultados");
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Reporte de Resultado");
				jLabel1.setBounds(44, 72, 138, 16);
				jLabel1.setFont(new java.awt.Font("Tahoma",1,11));
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Proyecto:");
				jLabel2.setBounds(26, 103, 62, 16);
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Rentabilidad");
				jButton1.setBounds(218, 100, 113, 23);
				jButton1.setBackground(new java.awt.Color(255,255,255));
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton1.actionPerformed, event="+evt);
						long idProy = Sistema.getInstancia().buscarIdProyecto(String.valueOf(jComboBox1.getSelectedItem()));
						jTextField1.setText(String.valueOf(Sistema.getInstancia().getReporteRentabilidad(idProy)));
					}
				});
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Productividad");
				jButton2.setBounds(350, 100, 121, 23);
				jButton2.setBackground(new java.awt.Color(255,255,255));
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton2.actionPerformed, event="+evt);
						long idProy = Sistema.getInstancia().buscarIdProyecto(String.valueOf(jComboBox1.getSelectedItem()));
						jTextField1.setText(String.valueOf(Sistema.getInstancia().getReporteProductivudad(idProy)));
					}
				});
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Grafica");
				jLabel3.setBounds(38, 296, 84, 28);
				jLabel3.setFont(new java.awt.Font("Segoe UI",0,24));
			}
			{
				jButton3 = new JButton();
				getContentPane().add(jButton3);
				jButton3.setText("Cerrar");
				jButton3.setBounds(390, 315, 71, 23);
				jButton3.setBackground(new java.awt.Color(255,255,255));
				jButton3.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton3.actionPerformed, event="+evt);
						System.out.println("botonCancelar.actionPerformed, event="+evt);
						Bienvenida b = Bienvenida.getinstancia(); 
						b.setLocationRelativeTo(null);
						b.setVisible(true);
						dispose();
					}
				});
			}
			{
				ComboBoxModel jComboBox1Model = 
					new DefaultComboBoxModel( proyectos );//TEndriamos que cargar los datos de la base de datos
				jComboBox1 = new JComboBox();
				getContentPane().add(jComboBox1);
				jComboBox1.setModel(jComboBox1Model);
				jComboBox1.setBounds(93, 100, 113, 23);
				jComboBox1.setBackground(new java.awt.Color(255,255,255));
			}
			{
				jButton4 = new JButton();
				getContentPane().add(jButton4);
				jButton4.setText("Exportar");
				jButton4.setBounds(257, 316, 94, 21);
				jButton4.setBackground(new java.awt.Color(255,255,255));
				jButton4.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton4.actionPerformed, event="+evt);
						//TODO boton para exporta a excel!!!
					}
				});
			}
			{
				jTextField1 = new JTextField();
				getContentPane().add(jTextField1);
				getContentPane().add(getJPanel1());
				jTextField1.setBounds(218, 210, 113, 23);
			}
			pack();
			this.setSize(513, 401);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private Logo getJPanel1() {
		if(jPanel1 == null) {
			jPanel1 = new Logo(false);
			jPanel1.setBounds(36, 5, 189, 50);
		}
		return jPanel1;
	}

}
